 <link rel="stylesheet" type="text/css" href="<?php echo $this->template->url_theme_admin; ?>css/jquery.masterblaster.css"/>
<script type="text/javascript" src="<?php echo $this->template->url_theme_admin; ?>js/tag/jquery.masterblaster.js"></script>

<ul id="myTab" class="nav nav-tabs pattern" style="margin-bottom: 0px;">
		<li class="active"><a href="#home" data-toggle="tab">Thông tin cơ bản</a></li>
			<li><a href="#link_download" data-toggle="tab">Link download</a></li>
			<li><a href="#seo" data-toggle="tab">SEO</a></li>
			<li><a href="#save" data-toggle="tab">Lưu</a></li>
</ul>
<form method="post" action="<?php echo $this->url_edit . @$soft->SOFT_ID; ?>"  enctype="multipart/form-data">
<div class="tab-content" style="margin-top: 0px;">
<div class="tab-pane fade in active" id="home">
    <div class="span12 ">
        
            <div class="table_head" style="margin-top: 0px;"><h6><i class="icon-list-alt"></i>
			<?php
			if(@$soft->SOFT_ID > 0)
			{
				echo 'Thông tin '.@$tresource->RES_NAME;
				
			}
			else {
				echo 'Thêm mới '.@$tresource->RES_NAME;
			}
			?></h6></div>
            <div class="subcont">
                <ul class="details span12">
                    <li><?php echo $this->atheme->group_single_upload('userfile', 'Ảnh đại diện', '', ' span6', @$soft->SOFT_THUMB, 'text', '80px','80px'); ?></li>
                    <li><?php echo $this->atheme->group_single_upload('iconsoft', 'Icon: ', '', ' span6', @$soft->SOFT_ICON, 'text', '80px','80px'); ?></li>
					
					 <li><?php echo $this->atheme->group_input2('searchscholarship', 'Nhà sản xuất', 'searchscholarship', 'required span6', @$manName, 'text', '');?> <input type="hidden" id="man_id" value="<?php echo @$soft->MAN_ID;?>" name="soft[MAN_ID]"></li>
					 
					 
					<li><?php //echo $this->atheme->group_select2('soft[MAN_ID]', 'Nhà sản xuất', '', 'required',$sman, @$soft->MAN_ID, ''); ?></li>
					
					<li><?php echo $this->atheme->group_select2('soft[LICE_ID]', 'Bản quyền: ', '', 'required',$slice, @$soft->LICE_ID, ''); ?></li>
					<li>
					<li>
					<div class="row-form">
					<div class="span3"><label for="txtCodeTitle">Tên danh mục *</label></div>
					<div class="span9">
					<select name="soft[CAT_ID]" id="soft[CAT_ID]" style="width:300px;">
						<?php
						foreach ($cate_tree as $cc) {
							echo '<optgroup label="'.$cc['name'].'">';
							
							if(count($cc['sub']) > 0) {
							foreach($cc['sub'] as $sub) {
								if (isset($sub['item'])) {
									echo '<option value="'.$sub['item']['CAT_ID'].'" ';
									if (@$soft->CAT_ID == $sub['item']['CAT_ID']) 
										echo ' selected="selected" ';
									echo '>'.$sub['item']['CAT_NAME'].'</option>';
									
									if (isset($sub['sub'])){
										foreach ($sub['sub'] as $k=>$v) {
											echo '<option value="'.$k.'" ';
											if (@$soft->CAT_ID == $k) 
												echo ' selected="selected" ';
											echo '>'.$v.'</option>';
										}
									}
								}
								
							}
							}
							echo '</optgroup>';
						}
						?>
					</select>
					</div>
					<div class="clear"></div>
				</div>
										
                       <?php // echo $this->atheme->group_select2('cate[CAT_PARENT]', 'Trạng thái', '', 'required ',$cate_tree, @$cate->CAT_PARENT, 'style="width:300px;"'); ?>
                    </li>
					<?php //echo $this->atheme->group_select2('soft[CAT_ID]', 'Danh mục: ', '', 'required',$scate, @$soft->CAT_ID, ''); ?></li>
					
					 <li><?php echo $this->atheme->group_input2('soft[SOFT_NAME]', 'Tên chương trình *', 'txtCodeTitle', 'required span6', @$soft->SOFT_NAME, 'text', '');?></li>
					 <li><?php echo $this->atheme->group_input2('soft[SOFT_NAME_DESCRIPTION]', 'Tên tiếng việt', '', ' span6', @$soft->SOFT_NAME_DESCRIPTION, 'text', '');?></li>
					 <li><?php echo $this->atheme->group_input2('soft[SOFT_FILESIZE]', 'Dung lượng', '', ' span6', @$soft->SOFT_FILESIZE, 'text', '');?></li>
					 <li><?php echo $this->atheme->group_input2('soft[SOFT_VIEW]', 'Lượt xem:', '', 'span6', @$soft->SOFT_VIEW, 'text', '');?></li>
					 <li><?php echo $this->atheme->group_input2('soft[SOFT_VERSION]', 'Version:', '', ' span6', @$soft->SOFT_VERSION, 'text', '');?></li>
					 <li><?php echo $this->atheme->group_input2('soft[SOFT_DOWN]', 'Lượt download:', '', 'span6', @$soft->SOFT_DOWN, 'text', '');?></li>
					<li><?php echo $this->atheme->group_input2('soft[SOFT_TIME_USE_LIMIT]', 'Thời gian dùng thử:', '', 'span6', @$soft->SOFT_TIME_USE_LIMIT, 'text', '');?></li>
					
					<?php 
					if(@$soft->SOFT_ID > 0) {
				?>
					<li><?php echo $this->atheme->group_input2('mtag', 'Tags: ', 'tags', 'span6 tags', '', 'text', '');?></li>
					<?php } ?>

					<li>Giới thiệu ngắn</li>
					<textarea class="required span12 ckeditor" name="soft[SOFT_CONTENT_SHORT]" id="editor2"><?php echo @$soft->SOFT_CONTENT_SHORT;?></textarea>
					
					<li>Nội dung</li>
					<textarea class="required span12 ckeditor" name="soft[SOFT_CONTENT]" id="editor1"><?php echo @$soft->SOFT_CONTENT;?></textarea>
					
					<script type="text/javascript">
					function InsertToContent(someText) {
					var editor = CKEDITOR.instances.editor1; 
					editor.insertHtml('<img src="'+someText+'"/>');
					}
								
                                 </script>   
	<?php 
		if(@$soft->SOFT_ID > 0) {
		?>
								<div class="content noPad clearfix">
                                    <table cellpadding="0" cellspacing="0" border="0" class="responsive dynamicTable display table table-bordered" width="95%" id="imageslist">
                                        <thead>
                                        	<tr>
                                             <th  class="first-col" style="text-align:center; border-left:1px solid #dddddd;">Stt</th>
                                                <th>Link URL</th>        
                                                <th width="256">Hình ảnh</th> 
                                                 <th width="">Chèn hình</th>             
                                                <th width="5%">Xóa</th> 
                                            </tr>  
                                        </thead>
                                        <tbody>
                                        <?php 
										if (isset($images) && $images!=NULL):

										$i=0;
											foreach ($images as $row){?>
											<tr>
												<td align="center" style="text-align:center; border-left:1px solid #dddddd;"><?php echo $i+1;?></td>
												<td><?php echo image_src($row->SOFT_PATCH);?></td>
												<td class="text-align-center" align="center"><a href="<?php echo image_src($row->SOFT_PATCH);?>" target="_blank"><img src="<?php echo image_src($row->SOFT_PATCH);?>" style="height:64px;"/></a></td>
												<td>

                                                        <a class="" onclick="InsertToContent($(this).attr('rel')); return false;" href="javascript:void(0);" rel="<?php echo image_src($row->SOFT_PATCH);?>"><span class="btn">Chèn</span></a>

                                                </td>
                                                <td>

                                                        <a class="tip deleteimage" href="javascript:void(0);" rel="<?php echo $row->SOFTI_ID?>">
                                                        	<span class="icon12 icomoon icon-remove"></span>
                                                         </a>

                                                </td>
											</tr>
											<?php $i++;}
											endif;
											?>
                                        </tbody>
                                     	<thead>
                                        	<tr>
                                            	<th colspan="5">
                                                	<div id="target"></div>
                                                </th>
                                            </tr>
                                        	<tr>
                                            	<th colspan="5">
                                                   <link href="<?php echo $this->template->url_theme_admin; ?>js/uploadify/uploadify.css" type="text/css" rel="stylesheet">
                            <script src="<?php echo $this->template->url_theme_admin; ?>js/uploadify/swfobject.js" type="text/javascript"></script>        
                            <script src="<?php echo $this->template->url_theme_admin; ?>js/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
          <div id="target" class="gridview-toolbar">

</div>





<div>
	<?php echo $this->session->flashdata('message'); 
?>
	<form method="post" action="<?php echo admin_url().'soft/do_upload_products_image/';?>"  enctype="multipart/form-data">

    <?php //echo form_open_multipart(admin_url().'soft/do_upload_products_image/');?>
      <?php echo form_upload(array('name' => 'imagesdetail', 'id' => 'upload'));?>
<!--      <input type="submit" value="Upload"/> -->
<!--      <a href="javascript:$('#uploadifyit').uploadifyUpload();" id="uploadfile" class="btn-big-grey" style="clear:both; margin-top:10px;"><span>Tải tệp tin lên server</span></a> -->
</form>
<?php 

//echo form_close();?>
</div>

<style>
#uniform-upload {width:120px;}
</style>
<script type="text/javascript">
	$("#").parent().width(120);
</script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
	$('#uploadfile').click(function(){
	
	//$('#upload').uploadifySettings('scriptData', obj);
	$('#upload').uploadifyUpload();
});

// Your paths to the uploadify.swf and cancelImg may need to be modified for your set up

$("#upload").uploadify({
	uploader: '<?php echo $this->template->url_theme_admin; ?>js/uploadify/uploadify.swf',
	script: '<?php echo admin_url().'soft/do_upload_products_image'; ?>',
	cancelImg: '<?php echo $this->template->url_theme_admin; ?>js/uploadify/cancel.png',
	folder: 'uploads/',
	scriptData: {'param1': '<?php echo @$soft->SOFT_ID;?>'},
	
	scriptAccess: 'always',
	removeCompleted:false,			
	multi: true,
	sizeLimit:1024000,
	fileDesc : 'jpg,png,gif,jpeg',
	fileExt : '*.jpg;*.png;*.gif;*.jpeg',
	wmode:'transparent',
	queueSizeLimit:100,
	buttonText: 'Select image file',
	auto:true,
/*	'onError'     : function (event,ID,fileObj,errorObj) {
	      alert(errorObj.type + ' Error: ' + errorObj.info);
    }, */
	'onOpen' : function(){} ,
	
	'onError' : function (a, b, c, d) {
		 if (d.status == 404)
				alert('Could not find upload script.');
		 else if (d.type === "HTTP")
				alert('error '+d.type+": "+d.status);
		 else if (d.type ==="File Size")
				alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');
		 else
				alert('error '+d.type+": "+d.text);
	}, 
	'onComplete'   : function (event, queueID, fileObj, response, data) {
	var raw = $.parseJSON(response);
	var html ='';
	html+='<tr>';
	html+='<td align="center" style="text-align:center; border-left:1px solid #dddddd;">'+raw.id+'</td>';
	html+='<td>'+raw.link+'</td>';
	html+='<td class="text-align-center" align="center"><a href="'+raw.link+'" target="_blank"><img src="'+raw.link+'" style="height:64px;"></a></td>';
	html+='<td> <a class="" onclick="InsertToContent($(this).attr(\'rel\')); return false;" href="javascript:void(0);" rel="'+raw.link+'"><span class="btn">Chèn</span></a></td>';
	html+='<td><a class="tip deleteimage" href="javascript:void(0);" rel="'+raw.id+'"><span class="icon12 icomoon icon-remove"></span></a></td>';
	//html+='<td><a class="tip deleteimage" href="#" rel="'+raw.id+'"><span class="icon12 icomoon-icon-remove"></span></a></td>';
	html+='</tr>';
	//$("#target").append(info);
	$('#imageslist tbody').append(html);
	/*
		$.post('<?php echo site_url('administrator/upload/uploadify'); ?>',{message: response},function(info){
				 //Add response returned by controller
			//	$("#target").html(response); 
				$("#target").append(info);
		});
	*/
		console.log(response);
	},
	 'onAllComplete': function(event,data){
	 /*
		$.ajax({
		  type: 'POST',
		  url: '<?php echo admin_url().'soft/getimagelist'?>',
		  data: 'id=<?php echo @$soft->SOFT_ID;?>',
		  success: function(data){
			var raw = $.parseJSON(data);
			$('#imageslist tbody').html('');
			for(var i = 0; i < raw.length; ++i) {
				
			}

			
				$('#imageslist tbody').html(data);
			}
		});
		*/
	 }

});
	$(".btn-big-grey").button();	
	
	$(".deleteimage").live("click", function(){
			var id=$(this).attr('rel');
			var my=$(this);
			$.ajax({
				  type: 'POST',
				  url: '<?php echo admin_url().'soft/deleteimage';?>',
				  data: 'id='+id,
				  success: function(data){
					  if (data.length<=0)
					  {
						 $(my).parent().parent().remove();	 
					  }
					  else
					  	alert(data);
				},
                error:function (xhr, ajaxOptions, thrownError){
                    alert(xhr.responseText);
                }    
			});
	return false;
		});
		
});
</script>
                                                </th>
                                            </tr>
                                        </thead>
                                    </table>
                                </div>
					
					<?php 
}?>
					
					<?php
			if(@$soft->SOFT_ID > 0)
			{
			?>
				 <li>
					<?php echo $this->atheme->group_text2( 'Ngày tạo: ', date("d/m/Y H:i:s",$soft->SOFT_TIME_CREATE)); ?>	
				</li>
				<li>
					<?php echo $this->atheme->group_text2( 'Ngày cập nhật: ', date("d/m/Y H:i:s",$soft->SOFT_TIME_UPDATE)); ?>	
				</li>
			
			<?php
				
			}
			?>
			<li>
					  <input type="submit" name="send" class="btn btn-primary" value="<?php
			if(@$soft->SOFT_ID > 0)
			{
				echo 'Lưu';
				
			}
			else {
				echo 'Thêm mới';
			}
			?>"/>
					 <a href="<?php echo $this->url_index;?>" class="btn">Trở ra</a>
					 </li>
                </ul>
                
               
                <br clear="both">

            </div>
    </div>
</div>

<div  class="tab-pane fade in" id="link_download">
<div class="span12 ">
        
            <div class="table_head" style="margin-top: 0px;"><h6><i class="icon-list-alt"></i>Link Download</h6></div>
            <div class="subcont">
			<?php 
					if(@$soft->SOFT_ID > 0) {
				?>
                <ul class="details span10" id="linkdownload_content">
					<?php 
					if(isset($links))
					foreach($links as $link){ ?>
					<li id="linkdown_<?php echo $link->LINK_ID;?>">
					 <?php echo $this->atheme->group_input2('link_name[]', 'Tên Link: ', '', 'span6', @$link->LINK_NAME, 'text', ''); ?>
					 <?php echo $this->atheme->group_input2('link_link[]', 'Link: ', '', 'span6', @$link->LINK_LINKDOWN, 'text', ''); ?>
					 <center><input type="button" class="btn btn-danger remove_link" value="Xóa" rel="<?php echo $link->LINK_ID;?>"></center>
					 </li>
					 <?php
					 }?>
					 <li>
					  <input type="button" class="btn add_link" value="Thêm link download">
					 </li>
                </ul>
					<?php }
					else {
					echo '<br>bạn phải thêm mới trước rồi mới thêm phần này<br>';
					}?>
					  <br clear="both">
            </div>
    </div>

</div>


<div  class="tab-pane fade in" id="seo">
<div class="span12 ">
        
            <div class="table_head" style="margin-top: 0px;"><h6><i class="icon-list-alt"></i>for SEO</h6></div>
            <div class="subcont">
                <ul class="details span10">
					 <li><div class="row-form">
    <div class="span3"><label for="txtCodeName">SEO URL *: </label></div>
    <div class="span9"><input type="text" id="txtCodeName" name="soft[SOFT_CODE]" class="required span6" value="<?php echo @$soft->SOFT_CODE;?>">
	<input type="checkbox" id="check_autocomplete" <?php echo (@$soft->SOFT_ID > 0)?'':'checked=" checked"';?> > <em>Bật/tắt tự động điền SEO bài viết</em>
	</div>
    <div class="clear"></div>
</div></li>
					 
					 <li><?php echo $this->atheme->group_input2('soft[SEO_H1]', 'SEO H1: ', '', 'span6', @$soft->SEO_H1, 'text', ''); ?></li>
					 <li><?php echo $this->atheme->group_input2('soft[SEO_KEYWORD]', 'SEO Keyword: ', '', ' span6', @$soft->SEO_KEYWORD, 'text', ''); ?></li>
					 <li><?php echo $this->atheme->group_input2('soft[SEO_DESCRIPTION]', 'SEO Description: ', '', 'span6', @$soft->SEO_DESCRIPTION, 'text', ''); ?></li>
					 <li><?php echo $this->atheme->group_input2('soft[SEO_METATITLE]', 'SEO Title: ', '', ' span6', @$soft->SEO_METATITLE, 'text', ''); ?></li>

                </ul>
                <br clear="both">

            </div>
    </div>

</div>
<div  class="tab-pane fade in" id="save">
<div class="span12 ">
       
            <div class="subcont">
			<ul class="details span10">
					 <li>
					  <input type="submit" name="send" class="btn btn-primary" value="<?php
			if(@$soft->SOFT_ID > 0)
			{
				echo 'Lưu';
				
			}
			else {
				echo 'Thêm mới';
			}
			?>"/>
					 <a href="<?php echo $this->url_index;?>" class="btn">Trở ra</a>
					 </li>
					 </ul>
			
                <br clear="both">

            </div>
    </div>

</div>
</div>
</form>

<script>
$(".add_link").live("click",function(){

			var tid = Math.floor(Math.random()*1000+0);
			var html = '<li id="linkdown_'+tid+'"><div class="row-form"><div class="span3"><label for="myid_79">Tên Link: </label></div><div class="span9"><input type="text" id="myid_79" name="link_name[]" class="span6 valid" value=""></div><div class="clear"></div></div><div class="row-form"><div class="span3"><label for="myid_51">Link: </label></div><div class="span9"><input type="text" id="myid_51" name="link_link[]" class="span6" value=""></div><div class="clear"></div></div><center><input type="button" class="btn btn-danger remove_link" value="Xóa" rel="'+tid+'"></center></li>';
			
			$("#linkdownload_content").prepend(html);
		});
		
$(".remove_link").live("click",function(){
	var link_id = $(this).attr("rel");
	$("#linkdown_"+link_id).remove();
});

CKEDITOR.replace('editor1', { height: 300 });
CKEDITOR.replace('editor2', { height: 100 });

$( "#searchscholarship" ).autocomplete({
      source: function(request, response) {
	  $.post( "<?php echo admin_url();?>manufacturer/ajax_search/title", { s: $( "#searchscholarship" ).val()})
		  .done(function( data ) {
			var raw = $.parseJSON(data);
			source  = [ ];
			mapping = { };
			for(var i = 0; i < raw.length; ++i) {
				source.push(raw[i].title);
				mapping[raw[i].title] = raw[i].id;
			}
			response(source);
		  });
		 
      },
	  select: function( event, ui ) {
	console.log(ui);
	$('#man_id').val(mapping[ui.item.label]);
	},
      minLength: 2,
    });
	

	
	
var $mb = $( "#tags" );
	$mb.masterblaster( {
	tagRules: {
		unique: true,
		minLength: 3
	}
});

$(".tags").autocomplete({
  source: function(request, response) {
  $.post( "<?php echo admin_url();?>soft/ajax_getTag", { 
		s: request.term ,dataType: "json"})
	  .done(function( data ) {
	  var raw = $.parseJSON(data);
			source  = [ ];
			mapping = { };
			for(var i = 0; i < raw.length; ++i) {
				source.push(raw[i]);
			}
			response(source);
	  
		console.log(data); 
	  });
	 
  },
  select: function( event, ui ) {
 // $mb.masterblaster( "push", ui.item.label );
		 console.log(ui);
	$("#tags").val('');
	//$('#man_id').val(mapping[ui.item.label]);
},
  minLength: 1,
});
<?php
if($tags)
foreach($tags as $tag){
?>
$mb.masterblaster( "push", "<?php echo $tag->TAG_NAME;?>" );

<?php
}
?>
$mb.on( "mb:add", function( e, tagName ) {
    console.info( "Added: tagName" );
	 $.post( "<?php echo admin_url();?>soft/ajax_addTag", {
		s: tagName ,softid: <?php echo (@$soft->SOFT_ID)?$soft->SOFT_ID:'0';?>})
	  .done(function( data ) {
	  });
});

$mb.on( "mb:remove", function( e, tagName ) {
    console.info( "Removed: tagName" );
	$.post( "<?php echo admin_url();?>soft/ajax_removeTag", {
		s: tagName ,softid: <?php echo (@$soft->SOFT_ID)?$soft->SOFT_ID:'0';?>})
	  .done(function( data ) {
	  });
});


</script>